require('page/common/top-head-menu/index.js')
require('page/common/head-search/index.js')
require('page/common/head-search/index.js')
require('page/common/footer/index.js')
require('page/common/inquery/index.js')
require('util/sass-compiled.css');
require('./index.css')
// import bxSlider from 'util/slider/jquery.bxslider.js'
import {setCookies} from "util/auth";
import validate from 'jquery-validation';
import tool from 'util/tool';
import _mm from 'util/mm.js';
import _all from 'service/all-service';

const page = {
    init() {
        this.bindEvent();
        this.loadThree();
        this.loadClassical();
        this.loadTypeList();
    },
    loadThree() {
        _all.getShuffling(res => {
            $('.img-introduce').html('');
            if (res.data.length !== 0) {
                for (let i = 0; i < res.data.length; i++) {
                    $('.img-introduce').append('<div class="pic img-item">' +
                        '<img src="' + res.data[i] + '" class="pic-image" alt="Pic"/>' +
                        '</div>')
                }
            }
        }, err => {
            tool.msgShakeLayer(err.message);
        });
    },
    loadClassical() {
        _all.getClassical(res =>{
            $('.product-btns').html('');
            if(res.data.length !== 0) {
                for (let i = 0; i < res.data.length; i++) {
                    $('.product-btns').append('<div class="pic img-item">' +
                        '<img class="pic-image" src="'+ res.data[i].url + '" alt="' + res.data[i].name + '">'+
                        '<span class="pic-caption top-to-bottom">' +
                        '<h1 class="pic-title">' + res.data[i].name + '</h1>' +
                        '</span>'+
                        '</div>')
                }
            }
        }, err => {
            tool.msgShakeLayer(err.message);
        })
    },
    loadTypeList() {
        _all.getIndexAllType(res => {
            const page = require('./typeList.string');
            $('.product-item').html(_mm.renderHtml(page, {data: res.data}));
        }, err => {
            tool.msgShakeLayer(err.message);
        })
    },
    bindEvent() {
        const _this = this;
        const pushNode = function () {
            tool.pushNode($(this));
        };
        $(document).on('click', '.product-click', pushNode);
    }
};

module.export = page.init();